﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArithmeticLibrary;
using ArithmeticLibrary.Visitors;

namespace Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Zadej vyraz: ");
            string input = Console.ReadLine(); ;

            // dokud neni zadane ukoncovaci slovo end
            while (input != "end")
            {
                try
                {
                    Expression expression = new Expression(input);

                    expression.Reduce();

                    Console.Write("Zadejte bod x: ");
                    double d = double.Parse(Console.ReadLine());

                    Console.WriteLine("{0} = {1:0.#####}", expression.ToString(), expression.Evaluate(d));

                    Console.Write("Zadej vyraz: ");
                    input = Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    input = Console.ReadLine();
                    continue;
                }
            }
            
        }
    }
}
